#include <bits/stdc++.h>

using namespace std;
const int len=5;
int main_1069()
{
    int N1,N2,diff;
    scanf("%d",&diff);
    char N_s[len]= {0},N1_s[len]= {0},N2_s[len]= {0};
    while (1)
    {

        sprintf(N_s,"%04d",diff);
        sort(N_s,N_s+len-1);
        strcpy(N1_s,N_s);
        sscanf(N1_s,"%d",&N1);
        sort(N_s,N_s+len-1,greater<char>());
        strcpy(N2_s,N_s);
        sscanf(N2_s,"%d",&N2);
        diff=N2-N1;
        printf("%s - %s = %04d\n",N2_s,N1_s,diff);
        if (diff==0||diff==6174)
        {
            break;
        }
    }
    return 0;
}
